# from flask import Flask
#
# app = Flask(__name__)

# @app.route('/')
# def hi():
#    return 'hi, world!'
#
# if __name__ == '__main__':
#    app.run()

# @app.route('/user/<string:id>')
# def index(id):
#     if id == '1/1':
#         return 'python'
#     if id == 2.1:
#         return 'django'
#     if id == 3:
#         return 'java'
#     if id == 4:
#         return 'flask'
#     return 'hi, world!'

from werkzeug.routing import BaseConverter
from flask import Flask

app = Flask(__name__)


class RegexConverter(BaseConverter):
    def __init__(self, url_map, regex):
        super(RegexConverter, self).__init__(url_map)
        self.regex = regex

    def to_python(self, value):
        print('to_python方法被调用')
        return value


app.url_map.converters['re'] = RegexConverter


@app.route('/index/<re("1\d{10}"):value>')
def index(value):
    print(value)
    return 'hi'


if __name__ == '__main__':
    app.run()
